package services;

import domain.entities.LaboratorioCentralDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class CentralLaboratoryCRUDService<LaboratorioCentral> implements CRUDService<LaboratorioCentral>{

    private LaboratorioCentralDAO laboratorioCentralDAO;
    private AddressService addressService;

    public CentralLaboratoryCRUDService() {
    }

    @Autowired
    public CentralLaboratoryCRUDService(LaboratorioCentralDAO laboratorioCentralDAO, AddressService addressService) {
        this.laboratorioCentralDAO = laboratorioCentralDAO;
        this.addressService = addressService;
    }

    @Override
    public <V extends Criteria> List<LaboratorioCentral> list(V criteria) {
        List<LaboratorioCentral> list = laboratorioCentralDAO.findAll();
        Iterator<LaboratorioCentral> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }

    public LaboratorioCentral findById(int id){
        return (LaboratorioCentral) laboratorioCentralDAO.findById(id);
    }

    public void save(LaboratorioCentral laboratorioCentral){
        laboratorioCentralDAO.attachDirty((domain.entities.LaboratorioCentral) laboratorioCentral);
    }

    public void delete(LaboratorioCentral laboratorioCentral) {
        laboratorioCentralDAO.delete((domain.entities.LaboratorioCentral) laboratorioCentral);
    }
}
